package com.cgsrp.cgsrp_shopping.controller;

import com.cgsrp.cgsrp_shopping.domain.Product;
import com.cgsrp.cgsrp_shopping.service.ProductService;
import com.cgsrp.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sell")
public class SellController {
    @Autowired
    private ProductService productService;

    @GetMapping("list")
    public Result list(
            @RequestParam()int userId,
            @RequestParam(defaultValue = "1")Integer curPage,
            @RequestParam(defaultValue = "5")Integer pageSize,
            @RequestParam(defaultValue="")String searchKey
    ){
        return productService.list(userId,curPage,pageSize,searchKey);
    }

    @PostMapping("add")
    public Result add(Product product,Integer userId){
        product.setCreatBy(userId);
        product.setState(0);
        return productService.add(product);
    }

    @PostMapping("del")
    public Result del(Integer productId){
        return productService.del(productId);
    }
    @PostMapping("up")
    public Result up(Integer productId){
        return productService.up(productId);
    }

    @PostMapping("update")
    public Result update(Product product,Integer userId){
        product.setCreatBy(userId);
        product.setState(0);
        return productService.update(product,userId);
    }
}
